package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person person=new Person("李四",33);
        System.out.println(person);
        Class cls=Class.forName("reflect.Person");
        Constructor c=cls.getConstructor(String.class,int.class);
        Object obj = c.newInstance("王五",66);
        System.out.println(obj);
        Constructor c2 = cls.getConstructor(String.class);
        Object obj2 = c2.newInstance("赵六");
        System.out.println(obj2);
    }
}
